// [THAM KHẢO - Java, KHÔNG chạy được trong Bedrock]
// File gốc: alats/module.class
// Bedrock Script API chỉ chạy JavaScript, không có JVM nên file .class này
// (thực chất là mã nguồn Java dạng text, không phải bytecode) không bao giờ
// có thể thực thi trong addon. Các ý tưởng hữu ích trong file này đã được
// viết lại hoàn toàn bằng JS thật và đưa vào hệ thống chính:
//   - Xem scripts/core/ChunkRequestCache.js (từ main.class - MainBridge)
//   - Xem scripts/config/PlayerConfigOverrides.js (từ config.class - Config)
//   - Xem scripts/core/ModuleRegistry.js (từ module.class + main2.class)
// File này được giữ nguyên chỉ để đối chiếu/tham khảo.

// module.class - Java-style module class
public class Module {
    private String id;
    private String name;
    private String version;
    private boolean enabled;
    private int priority;
    private List<String> dependencies;
    private Map<String, Object> config;
    private ModuleState state;
    
    public enum ModuleState {
        UNINITIALIZED,
        INITIALIZED,
        RUNNING,
        PAUSED,
        ERROR
    }
    
    public Module(String id, String name, String version) {
        this.id = id;
        this.name = name;
        this.version = version;
        this.enabled = true;
        this.priority = 0;
        this.dependencies = new ArrayList<>();
        this.config = new HashMap<>();
        this.state = ModuleState.UNINITIALIZED;
    }
    
    public void initialize() {
        if (this.state != ModuleState.UNINITIALIZED) {
            return;
        }
        this.state = ModuleState.INITIALIZED;
        System.out.println("Module " + this.name + " initialized");
    }
    
    public void start() {
        if (this.state == ModuleState.INITIALIZED || this.state == ModuleState.PAUSED) {
            this.state = ModuleState.RUNNING;
            System.out.println("Module " + this.name + " started");
        }
    }
    
    public void pause() {
        if (this.state == ModuleState.RUNNING) {
            this.state = ModuleState.PAUSED;
            System.out.println("Module " + this.name + " paused");
        }
    }
    
    public void stop() {
        if (this.state == ModuleState.RUNNING || this.state == ModuleState.PAUSED) {
            this.state = ModuleState.INITIALIZED;
            System.out.println("Module " + this.name + " stopped");
        }
    }
    
    public void destroy() {
        this.state = ModuleState.UNINITIALIZED;
        this.config.clear();
        System.out.println("Module " + this.name + " destroyed");
    }
    
    // Getters and setters
    public String getId() { return this.id; }
    public String getName() { return this.name; }
    public String getVersion() { return this.version; }
    public boolean isEnabled() { return this.enabled; }
    public void setEnabled(boolean enabled) { this.enabled = enabled; }
    public int getPriority() { return this.priority; }
    public void setPriority(int priority) { this.priority = priority; }
    public List<String> getDependencies() { return this.dependencies; }
    public void setDependencies(List<String> dependencies) { this.dependencies = dependencies; }
    public ModuleState getState() { return this.state; }
    
    public Object getConfig(String key) {
        return this.config.get(key);
    }
    
    public void setConfig(String key, Object value) {
        this.config.put(key, value);
    }
    
    public void setConfigs(Map<String, Object> configs) {
        this.config.putAll(configs);
    }
    
    public Map<String, Object> getAllConfigs() {
        return new HashMap<>(this.config);
    }
}